//
//  DKUnauthorizedMainHeadView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/24.
//

#import "DKUnauthorizedMainHeadView.h"
#import "DKHomeCircleView.h"


@interface DKUnauthorizedMainHeadView()
@property (nonatomic, strong)UIImageView * dk_userAvtarImgView;
@property (nonatomic, strong)UILabel * dk_userNameLab;
@property (nonatomic, strong)DKHomeCircleView * dk_HomeCircleView;
@end
@implementation DKUnauthorizedMainHeadView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.clearColor;
        [self dk_addSubView];
        [self makeUserInfo];
    }
    return self;
}
- (void)dk_addSubView{
    UIImageView * dk_userHeadBgImgView = [[UIImageView alloc] init];
    dk_userHeadBgImgView.userInteractionEnabled = YES;
    dk_userHeadBgImgView.image = DK_GetImage(@"dk_MainHeadBg");
    [self addSubview:dk_userHeadBgImgView];
    [dk_userHeadBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
    self.dk_userAvtarImgView = [[UIImageView alloc] init];
    self.dk_userAvtarImgView.userInteractionEnabled = YES;
    self.dk_userAvtarImgView.image = DK_GetImage(@"dk_MainDefaultAvatar");
    self.dk_userAvtarImgView.layer.cornerRadius = DK_IsWidthScale(25);
    self.dk_userAvtarImgView.clipsToBounds = YES;
    [self addSubview:self.dk_userAvtarImgView];
    [self.dk_userAvtarImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(22)));
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.width.equalTo(@(DK_IsWidthScale(50)));
    }];
    self.dk_userNameLab = [[UILabel alloc] init];
    self.dk_userNameLab.textColor = DK_Hex(@"#333333");
    self.dk_userNameLab.font = DK_FONT_Medium(16);
    self.dk_userNameLab.numberOfLines = 0;
    [self addSubview:self.dk_userNameLab];
    [self.dk_userNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_userAvtarImgView.mas_right).offset(DK_IsWidthScale(10));
        make.right.equalTo(@(-DK_IsWidthScale(56)));
        make.top.equalTo(self.dk_userAvtarImgView).offset(DK_IsWidthScale(14));
    }];
    UIButton * dk_userInfoBtn = [[UIButton alloc] init];
    [dk_userInfoBtn setBackgroundImage:[UIImage imageNamed:@"dk_MainHeadInfo"] forState:UIControlStateNormal];
    [dk_userInfoBtn addTarget:self action:@selector(checkUserInfo) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_userInfoBtn];
    [dk_userInfoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.width.equalTo(@(DK_IsWidthScale(26)));
        make.height.equalTo(@(DK_IsWidthScale(26)));
    }];
    self.dk_HomeCircleView = [[DKHomeCircleView alloc] init];
    [self addSubview:self.dk_HomeCircleView];
    [self.dk_HomeCircleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(95)));
        make.right.equalTo(@(-DK_IsWidthScale(95)));
        make.top.equalTo(self.dk_userAvtarImgView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(115)));
    }];
}
- (void)makeUserInfo{
    DKUserBaseInfoModel * userBaseInfoMdl = [DKGlobalHelper defaultManager].userBaseInfoMdl;
    DKUserComplaintModel * userComplaintMdl = [DKGlobalHelper defaultManager].userComplaintMdl;

    if(userBaseInfoMdl.realName.length){
        self.dk_userNameLab.text = userBaseInfoMdl.realName;
    }else{
        self.dk_userNameLab.text = userBaseInfoMdl.phone;
    }
    self.dk_HomeCircleView.limitRemain = userBaseInfoMdl.unused;
    self.dk_HomeCircleView.limitFrozen = userComplaintMdl.locking;
    self.dk_HomeCircleView.limitUserd = userComplaintMdl.used;
    self.dk_HomeCircleView.limitAvailable = userComplaintMdl.unused;
    self.dk_HomeCircleView.totalLimitValue = userComplaintMdl.total;
    [self.dk_HomeCircleView startUpdate];
}
- (void)checkUserInfo{
    if(self.CheckUserInfoBlock){
        self.CheckUserInfoBlock();
    }
}
@end
